package com.tiancheng.trade.payment.controller.admin;

import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.payment.enums.FlowStatusEnum;
import com.tiancheng.trade.payment.enums.QrAddnStatusEnum;
import com.tiancheng.trade.payment.enums.QrTradeStatusEnum;
import com.tiancheng.trade.payment.service.QrFlowService;
import com.tiancheng.trade.payment.vo.admin.QrFlowQueryVo;
import com.tiancheng.trade.payment.vo.admin.res.QrFlowDetailQueryResVO;
import com.tiancheng.trade.payment.vo.admin.res.QrFlowQueryResVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: likailun
 * @Description: 二维码消费
 * @Date: create in 2021/8/28 9:45 上午
 */

@RestController
@RequestMapping("/admin/qrFlow")
@Validated
@Slf4j
public class QrFlowAdminController {

    @Resource
    private QrFlowService qrFlowService;


    /**
     * 分页查询支付流水
     *
     * @param qrFlowQueryVo
     * @return
     */
    @GetMapping("/findPageList")
    public Result<PageInfo<QrFlowQueryResVO>> findPageList(QrFlowQueryVo qrFlowQueryVo) {
        return Result.success(qrFlowService.findPageList(qrFlowQueryVo));
    }

    /**
     * 分页查询支付流水
     *
     * @param flowId
     * @return
     */
    @GetMapping("/detail/{flowId}")
    public Result<QrFlowDetailQueryResVO> detail(@PathVariable("flowId") String flowId) {
        return Result.success(qrFlowService.detail(flowId));
    }

    /**
     * 查询条件枚举
     *
     * @return
     */
    @GetMapping("/getQueryEnum")
    public Result<Map<String,Object>> getQueryEnum() {
        final Map<String, Object> result = new HashMap<>();
        result.put("trade_status", Arrays.stream(QrTradeStatusEnum.values()).map(e-> {
            final Map<String, Object> map = new HashMap<>();
            map.put("code",e.getCode());
            map.put("desc",e.getDesc());
            return map;
        }).collect(Collectors.toList()));
        result.put("addn_status", Arrays.stream(QrAddnStatusEnum.values()).map(e-> {
            final Map<String, Object> map = new HashMap<>();
            map.put("code",e.getCode());
            map.put("desc",e.getDesc());
            return map;
        }).collect(Collectors.toList()));
        result.put("pay_status", Arrays.stream(FlowStatusEnum.values()).map(e-> {
            final Map<String, Object> map = new HashMap<>();
            map.put("code",e.getCode());
            map.put("desc",e.getDesc());
            return map;
        }).collect(Collectors.toList()));
        return Result.success(result);
    }


}
